package br.com.formulavendas.businessusercase;
// default package

import java.util.List;

import org.hibernate.LockOptions;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import br.com.formulavendas.domainmodel.Perfil;

/**
 	* A data access object (DAO) providing persistence and search support for Perfil entities.
 			* Transaction control of the save(), update() and delete() operations 
		can directly support Spring container-managed transactions or they can be augmented	to handle user-managed Spring transactions. 
		Each of these methods provides additional information for how to configure it for the desired type of transaction control. 	
	 * @see .Perfil
  * @author MyEclipse Persistence Tools 
 */
public class ManterPerfil 
	extends BaseBusinessUserCase  
	implements br.com.formulavendas.businessusercase.baseinterface.IBasePersistence<Perfil>,
	br.com.formulavendas.businessusercase.baseinterface.IBaseFind<Perfil>{
	
	     private static final Logger log = LoggerFactory.getLogger(ManterPerfil.class);
	     
		//property constants
	public static final String NOME = "nome";
	public static final String DESCRICAO = "descricao";



    
    public void save(Perfil transientInstance) {
        log.debug("saving Perfil instance");
        try {
            this._session.save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(Perfil persistentInstance) {
        log.debug("deleting Perfil instance");
        try {
            this._session.delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public Perfil findById( java.lang.Integer id) {
        log.debug("getting Perfil instance with id: " + id);
        try {
            Perfil instance = (Perfil) this._session
                    .get("Perfil", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(Perfil instance) {
        log.debug("finding Perfil instance by example");
        try {
            List results = this._session
                    .createCriteria("Perfil")
                    .add(Example.create(instance))
            .list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding Perfil instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from Perfil as model where model." 
         						+ propertyName + "= ?";
         Query queryObject = this._session.createQuery(queryString);
		 queryObject.setParameter(0, value);
		 return queryObject.list();
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	public List findByNome(Object nome
	) {
		return findByProperty(NOME, nome
		);
	}
	
	public List findByDescricao(Object descricao
	) {
		return findByProperty(DESCRICAO, descricao
		);
	}
	

	public List findAll() {
		log.debug("finding all Perfil instances");
		try {
			String queryString = "from Perfil";
	         Query queryObject = this._session.createQuery(queryString);
			 return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
    public Perfil merge(Perfil detachedInstance) {
        log.debug("merging Perfil instance");
        try {
            Perfil result = (Perfil) this._session
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(Perfil instance) {
        log.debug("attaching dirty Perfil instance");
        try {
            this._session.saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(Perfil instance) {
        log.debug("attaching clean Perfil instance");
        try {
                      	this._session.buildLockRequest(LockOptions.NONE).lock(instance);
          	            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
}